package com.mathlearning.auth.service;

import com.mathlearning.auth.entity.*;
import com.mathlearning.auth.repository.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class HomeService {

    @Autowired
    private BannerRepository bannerRepository;

    @Autowired
    private LearningPlanRepository learningPlanRepository;

    @Autowired
    private LearningTopicRepository learningTopicRepository;

    @Autowired
    private CourseRepository courseRepository;

    @Autowired
    private DailyProblemRepository dailyProblemRepository;

    @Autowired
    private UserStatsRepository userStatsRepository;

    /**
     * 获取轮播图列表
     */
    public List<Banner> getBanners() {
        return bannerRepository.findByStatusOrderBySortOrderAscIdDesc(1);
    }

    /**
     * 获取学习计划列表
     */
    public List<LearningPlan> getLearningPlans() {
        return learningPlanRepository.findByStatusOrderByIdDesc(1);
    }

    /**
     * 获取学习主题列表
     */
    public List<LearningTopic> getLearningTopics() {
        return learningTopicRepository.findByStatusOrderBySortOrderAscIdDesc(1);
    }

    /**
     * 根据分类获取学习主题
     */
    public List<LearningTopic> getLearningTopicsByCategory(String category) {
        return learningTopicRepository.findByCategoryAndStatusOrderBySortOrderAsc(category, 1);
    }

    /**
     * 获取特色课程列表
     */
    public List<Course> getFeaturedCourses() {
        return courseRepository.findByStatusAndIsFeaturedOrderBySortOrderAscIdDesc(1, 1);
    }

    /**
     * 获取所有课程列表
     */
    public List<Course> getCourses() {
        return courseRepository.findByStatusOrderBySortOrderAscIdDesc(1);
    }

    /**
     * 获取今日每日一题
     */
    public DailyProblem getTodayDailyProblem() {
        return dailyProblemRepository.findByDate(LocalDate.now()).orElse(null);
    }

    /**
     * 获取用户学习统计
     */
    public UserStats getUserStats(Long userId) {
        return userStatsRepository.findByUserId(userId).orElse(null);
    }
}









